<template>
	<view class="pad-lr-30">
		<textarea name="" class="textarea mar-top-30 width-100" v-model="content" id="" placeholder="展开说说对该商品的想法吧..." maxlength="-1" cols="30" rows="10"></textarea>
		<view class="mar-top-30 fontSize-28 col-6">点击上传图片，会更能帮助其他用户哦~</view>
		<view class="pad-tb-40 borderbottom">
			<o-upload :imageHeight="200" :maxFile="3" @success="successimg" @remove="remove"></o-upload>
		</view>
		<view class="mar-top-30 radius-16 bgfff display align-items">
			<image :src="info?.image_text" class="proudct-item-icon-6 radius-16" mode=""></image>
			<view class="ml20 right_width">
				<view class="display-sb align-items">
					<view class="text-clamp-1 fontSize-28">{{info?.name}}</view>
					<view class=" fontSize-28 col-E23737">￥{{info?.price}}</view>
				</view>
				<view class="display align-items mar-top-42 fontSize-26 col-6">
					<text>{{info?.sku_name}}</text><text class="ml16">x{{info?.num}}</text>
				</view>
			</view>
		</view>
		<view class="display align-items mar-top-40">
			<view class="fontSize-30">综合评价</view>
			<uni-rate :size="30" activeColor="#F6911B" allowHalf class="ml20" v-model="value" />
		</view>
		<view class="text-align-center col-f fontSize-32 radius-40 fa_btn" @click="_evaluate_submit">
			发布
		</view>
	</view>
</template>

<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import {orderInfo,subGoodsEvaluate} from '@/utils/api'
onLoad((options)=>{
	order_goods_id.value = options.order_goods_id
	order_id.value = options.order_id
	_evaluate_page()
})
const order_id = ref()
const order_goods_id = ref()
//评价页面展示数据
const info = ref()
const content = ref()
const _evaluate_page =() =>{
	orderInfo({id:order_id.value}).then(res=>{
		if(res.code==1){
			res.data.goods.forEach(item=>{
				if(item.id==order_goods_id.value){
					info.value = item
				}
			})
		}
	})
}
const value = ref(3)
//上传图片
const images = ref()
const successimg =(e,fileList) =>{
	console.log(e,fileList,18)
	let imglist = []
	fileList.forEach(item=>{
		imglist.push(JSON.parse(item.response).data.file.url)
		images.value = imglist
	})
}
const remove = (e) =>{
	images.value=images.value.filter(item=>item!=e.url)
}
//发表
const _evaluate_submit =() =>{
	subGoodsEvaluate({
		id:order_goods_id.value,
		images:images.value?images.value.join(','):'',
		content:content.value,
		score:value.value
	}).then(res=>{
		uni.showToast({
				icon: 'none',
				title:res.msg
			})
		if(res.code==1){
			uni.$emit('updatapingjia')
			setTimeout(()=>{
				uni.navigateBack({
					delta:1
				})
			},1500)
		}
	})
}
</script>

<style lang="scss">
@import 'writeevaluate.scss';
</style>
